package com.lkm.market2_0.m_imple.steelyarddata;

import com.google.gson.Gson;
import com.lkm.frame.P;
import com.lkm.javatool.CollectionHelp;
import com.lkm.market2_0.ExpandConfig;
import com.lkm.market2_0.help.UIP;
import com.lkm.market2_0.m.steelyarddata.OnOrderAddEvent;
import com.lkm.market2_0.m.steelyarddata.OrderEntity;
import com.lkm.market2_0.m.steelyarddata.SteelyardDataModule;
import com.lkm.market2_0.task.DefaultTaskExecutor;




public class DataManager  {








    private DataManager(){}

    private Cache2SaveOrderTask cache2SaveOrderTask;
    DataManager(SteelyardDataModule steelyardDataModule) {
        cache2SaveOrderTask=new Cache2SaveOrderTask(this, steelyardDataModule, new DefaultTaskExecutor<Object[], Void, Boolean>(true), ExpandConfig.instance.getTaskManager2());
        cache2SaveOrderTask.action();
        cache2SaveOrderTask.execTask();
    }

    public UpOrdersTask updataData() {
        if (isUpdateIng()) return null;

        //P.p("====批量上传称重数据");
        UpOrdersTask updateDateTask = new UpOrdersTask();
        updateDateTask.setParam(null);
        updateDateTask.action();
        updateDateTask.execTask();
        return updateDateTask;
    }
    
    public boolean isUpdateIng(){
        return ExpandConfig.instance.getTaskManager2().getRunTask(UpOrdersTask.taskID())!=null;
    }




    public OrderEntity putData(String steelyardMac, OrderEntity orderEntity) {

        if (CollectionHelp.isEmpty(orderEntity.getGoods())) return null;


//            P.p(new Gson().toJson(goodEntitys));



        OnOrderAddEvent.send(steelyardMac, orderEntity);

//        TaskManager mTaskManager = Config.instance.getTaskManager2();




        cache2SaveOrderTask.add(orderEntity);

        if(P.isDebug()) {
            String log = "====新增订单："+new Gson().toJson(orderEntity);
            P.p(log+steelyardMac);
            if(UIP.isPrint()){
                UIP.p(log,steelyardMac);
            }
        }

        return orderEntity;
    }



}
